package com.wfk.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wfk.entity.BankType;
import com.wfk.mapper.BankTypeMapper;
import com.wfk.service.IBankTypeService;
import com.wfk.utils.BasePage;
import com.wfk.utils.ResponseData;

import cn.hutool.core.util.StrUtil;

/**
 * <p>
 * 银行基本类型 服务实现类
 * </p>
 *
 * @since 2019-01-07
 */
@Service
public class BankTypeServiceImpl extends ServiceImpl<BankTypeMapper, BankType> implements IBankTypeService {

	@Override
	public void getList(BankType bankType, BasePage<BankType> page) {
		QueryWrapper<BankType> ew = new QueryWrapper<BankType>();
		
		if(page.isPage()) {
			super.page(page, ew) ;
		}else {
			List<BankType> data = super.list(ew);
			int total = super.count(ew);
			page.setRecords(data) ;
			page.setTotal(total) ;
		}
	}

	@Override
	public ResponseData doBankTypeAdd(BankType bankType) {
		if(StrUtil.isBlank(bankType.getBankname())) {
			return ResponseData.baseError("类型名称不能为空") ;
		}
		if(StrUtil.isBlank(bankType.getLogo())) {
			return ResponseData.baseError("logo必须上传") ;
		}
		return super.save(bankType) ? ResponseData.ok() : ResponseData.baseError("添加失败") ;
	}

	@Override
	public ResponseData doBankTypeEdit(BankType bankType) {
		if(StrUtil.isBlank(bankType.getBankname())) {
			return ResponseData.baseError("类型名称不能为空") ;
		}
		if(StrUtil.isBlank(bankType.getLogo())) {
			return ResponseData.baseError("logo必须上传") ;
		}
		return super.updateById(bankType) ? ResponseData.ok() : ResponseData.baseError("修改失败") ;
	}
}
